/*
 * Copyright 2020 tu.cn All right reserved. This software is the
 * confidential and proprietary information of tu.cn ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Tu.cn
 */
package com.onedec.client.serviceImpl;

import com.onedec.client.entity.OnedecClient;
import com.onedec.client.entity.OnedecClientExample;
import com.onedec.client.mapper.OnedecClientMapper;
import com.onedec.client.service.ClientService;
import com.onedec.utils.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 31014
 * @date 2020/7/15 18:40
 */
@Service
public class ClientServiceImpl implements ClientService {

    @Resource
    private OnedecClientMapper onedecClientMapper;

    public void insertClient(OnedecClient onedecClient) {
        onedecClientMapper.insertSelective(onedecClient);
    }

    public PageBean<OnedecClient> selectClients(Integer page, Integer limit, OnedecClient onedecClient) {
        System.out.println(onedecClient);
        onedecClient.setClientBak1(page);
        onedecClient.setClientBak2(limit);
        final List<OnedecClient> clients = onedecClientMapper.selectByPage(onedecClient);
        final PageBean<OnedecClient> pageBean = new PageBean<>();
        final long count = onedecClientMapper.countByPage(onedecClient);
        pageBean.setData(clients);
        pageBean.setNumsOfCurrPage(clients.size());
        pageBean.setPage(page);
        pageBean.setPageSize(limit);
        pageBean.setTotalNum((int) count);
        return pageBean;
    }
}